package UIPanels;

import generalClasses.ProgramData;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

import MainApplication.DatePicker;

//VS4E -- DO NOT REMOVE THIS LINE!
//public class LocalPanel extends JPanel
/**
 * this panel display coupon table, supply interface for filtering the data
 * in the table, supply interface for choosing coupon and perform purchase of coupon.
 * this panel is suitable for all regions including group coupon interface.
 * @author Daniel
 *
 */
public class LocalPanel extends GeneralPanel
{

	private static final long serialVersionUID = 1L;
	public JTable jTable0;
	private JScrollPane jScrollPane0;
	private String[] colNames = {};
	private Object[][]  data = {} ;
	private int region;
	private JLabel jLabel0;
	private JLabel jLabel1;
	private JButton jButton0;
	private JButton jButton1;
	private JTextArea jTextArea0;
	private JScrollPane jScrollPane1;
	private JLabel jLabel2;
	
	private boolean _runOnceGroupCoupon;
	private boolean _runOnceSingleCoupon;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JButton jButton2;
	private JTextField jTextField0;
	private JComboBox jComboBox0;
	private JButton jButton3;
	private JTextField jTextField1;
	private JTextField jTextField2;
	private JTextField jTextField3;
	private JLabel jLabel7;
	private JLabel jLabel8;
	private JButton jButton4;
	

	/**
	 * Constructor for local panel with no parameters.
	 * this function is used only for development need. to show panel with no frame running. 
	 * 
	 */
	public LocalPanel()
	{

		initComponents();

	}
	
	
	/**
	 * Constructor for local panel with  parameters.
	 * 
	 * @param columNames - header,names of columns
	 * @param tableData - data of coupons for displaying in table
	 * @param localserver - the region number for which the panel was called
	 */
	public LocalPanel(String[] columNames, Object[][] tableData, int localserver)
	{
		this._runOnceGroupCoupon = false;
		this._runOnceSingleCoupon = false;
		initComponents(columNames,tableData, localserver);
	}

	/**
	 * @return the _runOnceGroupCoupon
	 */
	public boolean isRunOnceGroupCoupon()
	{
		return _runOnceGroupCoupon;
	}

	/**
	 * @param _runOnceGroupCoupon the _runOnceGroupCoupon to set
	 */
	public void setRunOnceGroupCoupon(boolean runOnceGroupCouponValue)
	{
		this._runOnceGroupCoupon = runOnceGroupCouponValue;
	}

	/**
	 * @return the _runOnceSingleCoupon
	 */
	public boolean isRunOnceSingleCoupon()
	{
		return _runOnceSingleCoupon;
	}

	/**
	 * @param _runOnceSingleCoupon the _runOnceSingleCoupon to set
	 */
	public void setRunOnceSingleCoupon(boolean runOnceSingleCouponValue)
	{
		this._runOnceSingleCoupon = runOnceSingleCouponValue;
	}

	/**
	 * this function initiate all components at the panel.sets initial values and locating them on the
	 * panel.inserting the data from database that relevant for the current user.
	 * @param columNames - header,names of columns
	 * @param tableData - data of coupons for displaying in table
	 * @param localserver - the region number for which the panel was called
	 */
	private void initComponents(String[] columNames, Object[][] tableData, int localserver) {
		colNames = columNames;
		data = tableData;
		region = localserver;
		setLayout(new GroupLayout());
		add(getJScrollPane0(), new Constraints(new Leading(33, 825, 10, 10), new Leading(94, 173, 12, 12)));
		add(getJLabel1(), new Constraints(new Leading(199, 492, 12, 12), new Leading(30, 10, 10)));
		add(getJLabel3(), new Constraints(new Leading(321, 12, 12), new Leading(290, 10, 10)));
		add(getJScrollPane1(), new Constraints(new Leading(163, 579, 10, 10), new Leading(555, 39, 10, 10)));
		add(getPurchaseButton(), new Constraints(new Leading(33, 150, 12, 12), new Leading(464, 10, 10)));
		add(getBackButton(), new Constraints(new Leading(221, 10, 10), new Leading(464, 10, 10)));
		add(getJLabel2(), new Constraints(new Leading(319, 253, 12, 12), new Leading(503, 25, 10, 10)));
		add(getJLabel4(), new Constraints(new Leading(33, 12, 12), new Leading(338, 10, 10)));
		add(getJLabel5(), new Constraints(new Leading(33, 12, 12), new Leading(373, 12, 12)));
		add(getJLabel6(), new Constraints(new Leading(33, 12, 12), new Leading(408, 12, 12)));
		add(getJButton2(), new Constraints(new Leading(88, 12, 12), new Leading(403, 10, 10)));
		add(getCategoryComboBox0(), new Constraints(new Leading(163, 12, 12), new Leading(335, 12, 12)));
		add(getDateFromField(), new Constraints(new Leading(163, 100, 10, 10), new Leading(408, 10, 10)));
		add(getJButton3(), new Constraints(new Leading(283, 10, 10), new Leading(402, 12, 12)));
		add(getDateToField(), new Constraints(new Leading(343, 109, 10, 10), new Leading(408, 12, 12)));
		add(getPriceFromField(), new Constraints(new Leading(163, 100, 12, 12), new Leading(373, 12, 12)));
		add(getPriceToField(), new Constraints(new Leading(345, 104, 12, 12), new Leading(373, 12, 12)));
		add(getJLabel7(), new Constraints(new Leading(301, 12, 12), new Leading(375, 12, 12)));
		add(getJLabel8(), new Constraints(new Leading(104, 12, 12), new Leading(375, 12, 12)));
		add(getGoButton(), new Constraints(new Leading(507, 77, 10, 10), new Leading(338, 91, 12, 12)));
		setSize(914, 645);
		
		jButton2.addActionListener(new ActionListener() {
	          public void actionPerformed(ActionEvent ae) {
	        	  jTextField0.setText(new DatePicker().setPickedDate());
			          }
			  });
		
		jButton3.addActionListener(new ActionListener() {
	          public void actionPerformed(ActionEvent ae) {
	        	  jTextField1.setText(new DatePicker().setPickedDate());
			          }
			  });
	}

	public int getRegion()
	{
		return region;
	}
	private JScrollPane getJScrollPane0() {
		if (jScrollPane0 == null) {
			jScrollPane0 = new JScrollPane();
			jScrollPane0.setForeground(new Color(0, 128, 255));
			jScrollPane0.setViewportView(getJTable0());
			jScrollPane0.addMouseListener(new MouseAdapter() {
	
			});
		}
		return jScrollPane0;
	}
	public JTable getJTable0() {
		if (jTable0 == null) {
			jTable0 = new JTable(data,colNames);
			jTable0.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
			jTable0.setColumnSelectionAllowed(false);
			jTable0.setRowSelectionAllowed(true);
			
			/*jTable0.setModel(new DefaultTableModel(data,colNames) {
				private static final long serialVersionUID = 1L;
				Class<?>[] types = new Class<?>[] { Object.class, Object.class, };
	
				public Class<?> getColumnClass(int columnIndex) {
					return types[columnIndex];
				}
			});*/
		}
		return jTable0;
	}
	
	/**
	 * this function initiate all components at the panel.sets initial values and locating them on the
	 * panel
	 * this function is used only for development need. to show panel with no frame running. 
	 * 
	 */
	private void initComponents() {
		setLayout(new GroupLayout());
		add(getJScrollPane0(), new Constraints(new Leading(33, 825, 10, 10), new Leading(94, 173, 12, 12)));
		add(getJLabel1(), new Constraints(new Leading(199, 492, 12, 12), new Leading(30, 10, 10)));
		add(getJLabel3(), new Constraints(new Leading(321, 12, 12), new Leading(290, 10, 10)));
		add(getJScrollPane1(), new Constraints(new Leading(163, 579, 10, 10), new Leading(555, 39, 10, 10)));
		add(getPurchaseButton(), new Constraints(new Leading(33, 150, 12, 12), new Leading(464, 10, 10)));
		add(getBackButton(), new Constraints(new Leading(221, 10, 10), new Leading(464, 10, 10)));
		add(getJLabel2(), new Constraints(new Leading(319, 253, 12, 12), new Leading(503, 25, 10, 10)));
		add(getJLabel4(), new Constraints(new Leading(33, 12, 12), new Leading(338, 10, 10)));
		add(getJLabel5(), new Constraints(new Leading(33, 12, 12), new Leading(373, 12, 12)));
		add(getJLabel6(), new Constraints(new Leading(33, 12, 12), new Leading(408, 12, 12)));
		add(getJButton2(), new Constraints(new Leading(88, 12, 12), new Leading(403, 10, 10)));
		add(getCategoryComboBox0(), new Constraints(new Leading(163, 12, 12), new Leading(335, 12, 12)));
		add(getDateFromField(), new Constraints(new Leading(163, 100, 10, 10), new Leading(408, 10, 10)));
		add(getJButton3(), new Constraints(new Leading(283, 10, 10), new Leading(402, 12, 12)));
		add(getDateToField(), new Constraints(new Leading(343, 109, 10, 10), new Leading(408, 12, 12)));
		add(getPriceFromField(), new Constraints(new Leading(163, 100, 12, 12), new Leading(373, 12, 12)));
		add(getPriceToField(), new Constraints(new Leading(345, 104, 12, 12), new Leading(373, 12, 12)));
		add(getJLabel7(), new Constraints(new Leading(301, 12, 12), new Leading(375, 12, 12)));
		add(getJLabel8(), new Constraints(new Leading(104, 12, 12), new Leading(375, 12, 12)));
		add(getGoButton(), new Constraints(new Leading(507, 77, 10, 10), new Leading(338, 91, 12, 12)));
		setSize(914, 645);
	}
	public JButton getGoButton() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setFont(new Font("Dialog", Font.BOLD, 28));
			jButton4.setText("Go");
		}
		return jButton4;
	}
	private JLabel getJLabel8() {
		if (jLabel8 == null) {
			jLabel8 = new JLabel();
			jLabel8.setText("From");
		}
		return jLabel8;
	}
	private JLabel getJLabel7() {
		if (jLabel7 == null) {
			jLabel7 = new JLabel();
			jLabel7.setText("To");
		}
		return jLabel7;
	}
	public JTextField getPriceToField() {
		if (jTextField3 == null) {
			jTextField3 = new JTextField();
		}
		return jTextField3;
	}
	public JTextField getPriceFromField() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
		}
		return jTextField2;
	}
	public JTextField getDateToField() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
		}
		return jTextField1;
	}
	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("To");
		}
		return jButton3;
	}
	public JComboBox getCategoryComboBox0() {
		if (jComboBox0 == null) {
			jComboBox0 = new JComboBox();
			jComboBox0.setModel(new DefaultComboBoxModel(ProgramData.getCategories()));
			jComboBox0.setDoubleBuffered(false);
			jComboBox0.setBorder(null);
		}
		return jComboBox0;
	}
	public JTextField getDateFromField() {
		if (jTextField0 == null) {
			jTextField0 = new JTextField();
		}
		return jTextField0;
	}
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("From");
		}
		return jButton2;
	}
	private JLabel getJLabel6() {
		if (jLabel6 == null) {
			jLabel6 = new JLabel();
			jLabel6.setForeground(new Color(0, 128, 255));
			jLabel6.setText("Date ");
		}
		return jLabel6;
	}
	private JLabel getJLabel5() {
		if (jLabel5 == null) {
			jLabel5 = new JLabel();
			jLabel5.setForeground(new Color(0, 128, 255));
			jLabel5.setText("Price ");
		}
		return jLabel5;
	}
	private JLabel getJLabel4() {
		if (jLabel4 == null) {
			jLabel4 = new JLabel();
			jLabel4.setForeground(new Color(0, 128, 255));
			jLabel4.setText("Category");
		}
		return jLabel4;
	}
	private JLabel getJLabel3() {
		if (jLabel3 == null) {
			jLabel3 = new JLabel();
			jLabel3.setFont(new Font("Dialog", Font.BOLD, 24));
			jLabel3.setForeground(new Color(0, 128, 255));
			jLabel3.setText("Coupon Filter");
		}
		return jLabel3;
	}
	private JLabel getJLabel2() {
		if (jLabel2 == null) {
			jLabel2 = new JLabel();
			jLabel2.setFont(new Font("Dialog", Font.BOLD, 24));
			jLabel2.setForeground(new Color(0, 128, 255));
			jLabel2.setText("Commercial Section ");
		}
		return jLabel2;
	}
	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setBackground(Color.lightGray);
			jScrollPane1.setViewportView(getJTextArea0());
		}
		return jScrollPane1;
	}
	public JTextArea getJTextArea0() {
		if (jTextArea0 == null) {
			jTextArea0 = new JTextArea();
			jTextArea0.setBackground(Color.lightGray);
			jTextArea0.setAutoscrolls(false);
			jTextArea0.setSelectedTextColor(new Color(128, 128, 255));
		}
		return jTextArea0;
	}
	public JButton getBackButton() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Back to Main Screen");
		}
		return jButton1;
	}
	public JButton getPurchaseButton() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setText("Purchase");
		}
		return jButton0;
	}
	private JLabel getJLabel1() {
		if (jLabel1 == null) {
			ProgramData pd = new ProgramData();
			String sregion = pd.regionToString(region);
			jLabel1 = new JLabel();
			jLabel1.setFont(new Font("Dialog", Font.BOLD, 36));
			jLabel1.setForeground(new Color(0, 128, 255));
			if (region == ProgramData.GENERAL)
			{
				jLabel1.setText("Available Group Coupons");
			}
			else
			{
				jLabel1.setText("Available Coupons at "+ sregion);
			}
			
		}
		return jLabel1;
	}
	
//	public String[] getRowAt(int row) {
//	     String[] result = new String[colNames.length];
//
//	     for (int i = 0; i < colNames.length; i++) {
//	         result[i] = (String) jTable0.getModel().getValueAt(row, i);
//	     }
//
//	     return result;
//	}
	
	
	 
	
	
	

}


